const app = getApp()
const util = require('../../utils/util.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        myData: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        //请求分享数据
        wx.request({
            url: app.globalData.ApiUrl + '/index.php?act=wx_share&op=get_share',
            data: {},
            method: 'GET',
            dataType: 'json',
            success: res => {
                if (res.data.code == '200') {
                    this.setData({
                        share_default_title: res.data.datas.title,
                        share_default_image_url: res.data.datas.imageUrl
                    })
                }
            }
        })
        util.share();
        let self = this;
        wx.getStorage({
            key: 'key',
            success: (res) => {
                self.setData({
                    member_key: res.data
                });
                this.getData();
            }
        })
    },
    /**
     * 获取数据
     */
    getData: function () {
        var self = this;
        //获取余额
        wx.request({
            url: app.globalData.ApiUrl + '/index.php?act=member_index&op=my_asset&key=' + self.data.member_key,
            success(res) {
                self.setData({
                    myData: res.data.datas
                });
            }
        });
    },
    onShareAppMessage: function () {
        let share_key = this.data.member_key ? this.data.member_key : '';
        let share_path = '';
        if (util.getCurrentPageUrlWithArgs().indexOf("?") != -1) {
            share_path = util.getCurrentPageUrlWithArgs() + '&share_key=' + share_key;
        } else {
            share_path = util.getCurrentPageUrlWithArgs() + '?share_key=' + share_key;
        }
        return {
            title: this.data.share_default_title,
            imageUrl: this.data.share_default_image_url,
            path: share_path
        }
    }
})